var _ajax = require('../../utils/ajax');
var _Server = require('../../utils/server');
var WxParse = require('../../wxParse/wxParse'); // 富文本转化插件
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        _ajax.myProductOrderDetails(options.orderId, function(data) {
            console.log(data);
            if (data.code == 0) {
                that.setData({
                    indexUrl: _Server.url,
                    myProductOrderData: data.data,
                    orderId: options.orderId
                });
            }
        }, this);
    },
    // 支付尾款
    fnBuyMoney: function(e) {
        var that = this;
        var orderId = that.data.orderId;
        _ajax.myProductPay(orderId, 1, function(data) {
            var data = data.data;
            wx.requestPayment({
                timeStamp: data.timeStamp,
                nonceStr: data.nonceStr,
                package: data.package,
                signType: data.signType,
                paySign: data.paySign,
                success(res) { // 支付成功回调
                    that.initData();
                },
                fail(res) {
                    wx.showToast({
                        title: '支付失败',
                        icon: 'loading',
                        duration: 800
                    });
                    setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 800);
                }
            })
        }, this);
    },
    initData: function(options) {
        var that = this;
        var orderId = that.data.orderId;
        _ajax.myProductOrderDetails(orderId, function(data) {
            if (data.code == 0) {
                that.setData({
                    indexUrl: _Server.url,
                    myProductOrderData: data.data
                });
            }
        }, this);
    },
})